var app = getApp();
// pages/user/myinvite.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    showLeft: true,
    teamRank: [],
    incomeMoney: 0,//可提现
    todayMoney: 0,//今日收益
    todayOrder: 0,//今日订单数
    totalOrder: 0,//总订单数
    todayMember: 0,//今日团员数
    totalMember: 0,//总团员数
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getData();
    this.getTeamRank();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  changeShowLeft: function () {
    var show = this.data.showLeft;
    this.setData({
      showLeft: !show
    })
  },
  getData: function () {
    var token = wx.getStorageSync("token");
    var that = this;

    var reqTask = wx.request({
      url: app.apiUrl("user/myinvite"),
      data: {},
      header: { 'content-type': 'application/json', "X-ECTouch-Authorization": token },
      method: 'POST',
      dataType: 'json',
      responseType: 'text',
      success: (result) => {
        console.log(result.data);
        that.setData({
          incomeMoney: result.data.data.incomeMoney,//可提现
          todayMoney: result.data.data.todayMoney,//今日收益
          todayOrder: result.data.data.todayOrder,//今日订单数
          totalOrder: result.data.data.totalOrder,//总订单数
          todayMember: result.data.data.todayMember,//今日团员数
          totalMember: result.data.data.totalMember,//总团员数
        });
      },
      fail: () => { },
      complete: () => { }
    });

  },
  getTeamRank: function () {
    var token = wx.getStorageSync("token");
    var that = this;

    var reqTask = wx.request({
      url: app.apiUrl("user/teamRank"),
      data: {},
      header: { 'content-type': 'application/json', "X-ECTouch-Authorization": token },
      method: 'POST',
      dataType: 'json',
      responseType: 'text',
      success: (result) => {
        console.log(result.data);
        that.setData({
          teamRank: result.data.data
        });
      },
      fail: () => { },
      complete: () => { }
    });

  },
  getUserRank: function () {
    var token = wx.getStorageSync("token");
    var that = this;

    var reqTask = wx.request({
      url: app.apiUrl("user/teamRank"),
      data: {},
      header: { 'content-type': 'application/json', "X-ECTouch-Authorization": token },
      method: 'POST',
      dataType: 'json',
      responseType: 'text',
      success: (result) => {
        console.log(result.data);
        that.setData({
          teamRank: result.data.data
        });
      },
      fail: () => { },
      complete: () => { }
    });
  },
})